<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="description" content="autopy module for working with bitmaps" />
    <title>
      bitmap — autopy module for working with bitmaps
    </title>
    <link rel="stylesheet" href="style.css" type="text/css" charset="utf-8" />
  </head>
  <body>
    <div id="header">
      <a href="#">AutoPy Documentation</a> » <a href="index.html">API Reference</a>
      <div id="nav">
        <a href="alert.html">previous</a> | <a href="index.html">index</a> | <a href="color.html">next</a>
      </div>
    </div>
    <div id="container">
      <div id="sidebar">
        <h3>
          Table of Contents
        </h3>
        <ul>
          <li>
            <a href="#module-bitmap">bitmap — autopy module for working with bitmaps</a>
            <ul>
              <li>
                <a href="#Bitmap_object_methods">Bitmap object methods</a>
                <ul>
                  <li>
                    <a href="#bmp.get_portion">bmp.get_portion</a>
                  </li>
                  <li>
                    <a href="#bmp.find_bitmap">bmp.find_bitmap</a>
                  </li>
                  <li>
                    <a href="#bmp.count_of_bitmap">bmp.count_of_bitmap</a>
                  </li>
                  <li>
                    <a href="#bmp.find_every_bitmap">bmp.find_every_bitmap</a>
                  </li>
                  <li>
                    <a href="#bmp.point_in_bounds">bmp.point_in_bounds</a>
                  </li>
                  <li>
                    <a href="#Bitmap.open">Bitmap.open</a>
                  </li>
                  <li>
                    <a href="#bmp.to_string">bmp.to_string</a>
                  </li>
                  <li>
                    <a href="#bmp.find_every_color">bmp.find_every_color</a>
                  </li>
                  <li>
                    <a href="#bmp.get_color">bmp.get_color</a>
                  </li>
                  <li>
                    <a href="#Bitmap.from_string">Bitmap.from_string</a>
                  </li>
                  <li>
                    <a href="#bmp.copy_to_pboard">bmp.copy_to_pboard</a>
                  </li>
                  <li>
                    <a href="#bmp.find_color">bmp.find_color</a>
                  </li>
                  <li>
                    <a href="#bmp.count_of_color">bmp.count_of_color</a>
                  </li>
                  <li>
                    <a href="#bmp.save">bmp.save</a>
                  </li>
                </ul>
              </li>
            </ul>
            <ul>
              <li>
                <a href="#Functions">Functions</a>
                <ul>
                  <li>
                    <a href="#capture_screen">capture_screen</a>
                  </li>
                </ul>
              </li>
            </ul>
          </li>
        </ul>
      </div>
      <div id="main">
        <h1 id="module-bitmap">
          bitmap — autopy module for working with bitmaps<a href="#module-bitmap" class="headerlink" title="Permalink to this headline">¶</a>
        </h1>
        <div class="description">
          <p>
            This module defines the class <tt class="mono">Bitmap</tt> for accessing bitmaps and searching for bitmaps on-screen.
          </p>
          <p>
            It also defines functions for taking screenshots of the screen.
          </p>
        </div>
        <h2 id="Bitmap_object_methods">
          Bitmap Object Methods<a href="#Bitmap_object_methods" class="headerlink" title="Permalink to this headline">¶</a>
        </h2>
        <dl class="section">
          <dt class="function" id="bmp.get_portion">
            <tt class="name">bmp.get_portion</tt><big>(</big><span class="funcarg">origin</span>, <span class="funcarg">size</span><big>)</big><a href="#bmp.get_portion" class="headerlink" title="Permalink to this headline">¶</a>
          </dt>
          <dd>
            <p>
              Returns new bitmap object created from a portion of another.
            </p>
            <div class="exceptions-header">
              Exceptions:
            </div>
            <ul class="exceptions">
              <li>
                <tt class="var">IOError</tt> is thrown if portion could not be copied.
              </li>
              <li>
                <tt class="var">ValueError</tt> is thrown if portion was out of bounds.
              </li>
            </ul>
          </dd>
          <dt class="function" id="bmp.find_bitmap">
            <tt class="name">bmp.find_bitmap</tt><big>(</big><span class="funcarg">needle</span>, <span class="funcarg">tolerance=0.0</span>, <span class="funcarg">rect=None</span><big>)</big><a href="#bmp.find_bitmap" class="headerlink" title="Permalink to this headline">¶</a>
          </dt>
          <dd>
            <p>
              Searches for <tt class="var">needle</tt> in <tt class="var">bmp</tt>. Returns tuple <tt class="mono">(x, y)</tt> of position if found, or <tt class="const">None</tt> if not.
            </p>
          </dd>
          <dt class="function" id="bmp.count_of_bitmap">
            <tt class="name">bmp.count_of_bitmap</tt><big>(</big><span class="funcarg">needle</span>, <span class="funcarg">tolerance=0.0</span>, <span class="funcarg">rect=None</span><big>)</big><a href="#bmp.count_of_bitmap" class="headerlink" title="Permalink to this headline">¶</a>
          </dt>
          <dd>
            <p>
              Returns count of occurrences of <tt class="var">needle</tt> in <tt class="var">haystack</tt>. Functionally equivalent to:
            </p>
            <pre>
len(bmp.find_every_bitmap(needle, tolerance))
</pre>
          </dd>
          <dt class="function" id="bmp.find_every_bitmap">
            <tt class="name">bmp.find_every_bitmap</tt><big>(</big><span class="funcarg">needle</span>, <span class="funcarg">tolerance=0.0</span>, <span class="funcarg">rect=None</span><big>)</big><a href="#bmp.find_every_bitmap" class="headerlink" title="Permalink to this headline">¶</a>
          </dt>
          <dd>
            <p>
              Returns list of all <tt class="mono">(x, y)</tt> coordinates where <tt class="var">needle</tt> occurs in <tt class="var">bmp</tt>.
            </p>
          </dd>
          <dt class="function" id="bmp.point_in_bounds">
            <tt class="name">bmp.point_in_bounds</tt><big>(</big><span class="funcarg">x</span>, <span class="funcarg">y</span><big>)</big><a href="#bmp.point_in_bounds" class="headerlink" title="Permalink to this headline">¶</a>
          </dt>
          <dd>
            <p>
              Returns <tt class="const">True</tt> if <tt class="mono">x &lt; bmp.width</tt> and <tt class="mono">y &lt; bmp.height</tt>, or <tt class="const">False</tt> if not.
            </p>
          </dd>
          <dt class="function" id="Bitmap.open">
            <tt class="class-name">bitmap.</tt><tt class="name">Bitmap.open</tt><big>(</big><span class="funcarg">filepath</span>, <span class="funcarg">format</span><big>)</big><a href="#Bitmap.open" class="headerlink" title="Permalink to this headline">¶</a>
          </dt>
          <dd>
            <p>
              Opens image at absolute filepath in the given format. The image type is determined from the filename if possible, unless <tt class="var">format</tt> is given.
            </p>
            <div class="exceptions-header">
              Exceptions:
            </div>
            <ul class="exceptions">
              <li>
                <tt class="var">IOError</tt> is thrown if the image could not be opened.
              </li>
            </ul>
          </dd>
          <dt class="function" id="bmp.to_string">
            <tt class="name">bmp.to_string</tt><big>(</big><big>)</big><a href="#bmp.to_string" class="headerlink" title="Permalink to this headline">¶</a>
          </dt>
          <dd>
            <p>
              Returns compressed, printable string representing bitmap, to be used with <tt class="mono"><a href="#Bitmap.from_string">Bitmap.from_string()</a></tt>.
            </p>
            <div class="exceptions-header">
              Exceptions:
            </div>
            <ul class="exceptions">
              <li>
                <tt class="var">IOError</tt> is thrown if the string could not be created.
              </li>
            </ul>
          </dd>
          <dt class="function" id="bmp.find_every_color">
            <tt class="name">bmp.find_every_color</tt><big>(</big><span class="funcarg">color</span>, <span class="funcarg">tolerance=0.0</span>, <span class="funcarg">rect=None</span><big>)</big><a href="#bmp.find_every_color" class="headerlink" title="Permalink to this headline">¶</a>
          </dt>
          <dd>
            <p>
              Returns list of all coordinates inside <tt class="var"><tt class="keyword">rect</tt></tt> in <tt class="var">bmp</tt> matching <tt class="var">color</tt>. If <tt class="var"><tt class="keyword">rect</tt></tt> is <tt class="const">None</tt>, the entire image is searched.
            </p>
          </dd>
          <dt class="function" id="bmp.get_color">
            <tt class="name">bmp.get_color</tt><big>(</big><span class="funcarg">x</span>, <span class="funcarg">y</span><big>)</big><a href="#bmp.get_color" class="headerlink" title="Permalink to this headline">¶</a>
          </dt>
          <dd>
            <p>
              Returns hexadecimal value describing the RGB color at the given point.
            </p>
            <div class="exceptions-header">
              Exceptions:
            </div>
            <ul class="exceptions">
              <li>
                <tt class="var">ValueError</tt> is thrown if the point out of bounds.
              </li>
            </ul>
          </dd>
          <dt class="function" id="Bitmap.from_string">
            <tt class="class-name">bitmap.</tt><tt class="name">Bitmap.from_string</tt><big>(</big><span class="funcarg">string</span><big>)</big><a href="#Bitmap.from_string" class="headerlink" title="Permalink to this headline">¶</a>
          </dt>
          <dd>
            <p>
              Creates bitmap from string created by <tt class="mono"><a href="#bmp.to_string">bmp.to_string()</a></tt>.
            </p>
            <div class="exceptions-header">
              Exceptions:
            </div>
            <ul class="exceptions">
              <li>
                <tt class="var">ValueError</tt> is thrown if the given string was invalid.
              </li>
            </ul>
          </dd>
          <dt class="function" id="bmp.copy_to_pboard">
            <tt class="name">bmp.copy_to_pboard</tt><big>(</big><big>)</big><a href="#bmp.copy_to_pboard" class="headerlink" title="Permalink to this headline">¶</a>
          </dt>
          <dd>
            <p>
              Copies image to pasteboard. Currently only supported on Windows and Mac OS X.
            </p>
            <div class="exceptions-header">
              Exceptions:
            </div>
            <ul class="exceptions">
              <li>
                <tt class="var">OSError</tt> is thrown if the image could not be copied.
              </li>
            </ul>
          </dd>
          <dt class="function" id="bmp.find_color">
            <tt class="name">bmp.find_color</tt><big>(</big><span class="funcarg">color</span>, <span class="funcarg">tolerance=0.0</span>, <span class="funcarg">rect=None</span><big>)</big><a href="#bmp.find_color" class="headerlink" title="Permalink to this headline">¶</a>
          </dt>
          <dd>
            <p>
              Attempts to find color inside <tt class="var"><tt class="keyword">rect</tt></tt> in <tt class="var">bmp</tt>; returns coordinates if found, or <tt class="const">None</tt> if not. If <tt class="var"><tt class="keyword">rect</tt></tt> is <tt class="const">None</tt>, the entire image is searched.
            </p>
          </dd>
          <dt class="function" id="bmp.count_of_color">
            <tt class="name">bmp.count_of_color</tt><big>(</big><span class="funcarg">color</span>, <span class="funcarg">tolerance=0.0</span>, <span class="funcarg">rect=None</span><big>)</big><a href="#bmp.count_of_color" class="headerlink" title="Permalink to this headline">¶</a>
          </dt>
          <dd>
            <p>
              Returns count of color in bitmap. Functionally equivalent to:
            </p>
            <pre>
len(find_every_color(color, tolerance, rect))
</pre>
          </dd>
          <dt class="function" id="bmp.save">
            <tt class="name">bmp.save</tt><big>(</big><span class="funcarg">filepath</span>, <span class="funcarg">[format]</span><big>)</big><a href="#bmp.save" class="headerlink" title="Permalink to this headline">¶</a>
          </dt>
          <dd>
            <p>
              Saves image to absolute filepath in the given format. The image type is determined from the filename if possible, unless <tt class="var">format</tt> is given. Note that if the file already exists, it WILL be overwritten. Check yourself first if you do not desire this.
            </p>
            <div class="exceptions-header">
              Exceptions:
            </div>
            <ul class="exceptions">
              <li>
                <tt class="var">IOError</tt> is thrown if the image could not be saved.
              </li>
            </ul>
          </dd>
        </dl>
        <h2 id="Functions">
          Functions<a href="#Functions" class="headerlink" title="Permalink to this headline">¶</a>
        </h2>
        <dl class="section">
          <dt class="function" id="capture_screen">
            <tt class="class-name">bitmap.</tt><tt class="name">capture_screen</tt><big>(</big><span class="funcarg">rect=None</span><big>)</big><a href="#capture_screen" class="headerlink" title="Permalink to this headline">¶</a>
          </dt>
          <dd>
            <p>
              Returns a screengrab of the given portion of the main display, or the entire display if <tt class="var"><tt class="keyword">rect</tt></tt> is <tt class="const">None</tt>.
            </p>
            <div class="exceptions-header">
              Exceptions:
            </div>
            <ul class="exceptions">
              <li>
                <tt class="var">OSError</tt> is thrown if the screengrab was unsuccessful.
              </li>
              <li>
                <tt class="var">ValueError</tt> is thrown if the <tt class="keyword">rect</tt> is out of bounds.
              </li>
            </ul>
          </dd>
        </dl>
      </div>
    </div>
  </body>
</html>
